package com.autoTools.view;

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Component;
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import com.autoTools.util.Constants;
import com.autoTools.util.LogUtil;

public class FrameView extends BaseView
{
	private Frame mFrame = null;

	public FrameView()
	{
		mFrame = new Frame();
		mFrame.setEnabled(true);
		mFrame.setVisible(true);
		mFrame.setBounds(100, 100, 800, 600);
		mFrame.addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent evt)
			{
				mFrame.setVisible(false); 
				mFrame.dispose(); 
				System.exit(0); 
			}
		});
		BaseInit(mFrame);
	}

	public boolean addChild(BaseView child)
	{
		boolean state = false;
		if (child != null)
		{
			if (child.getParent() != null)
			{
				state = false;
			}else{
				if(child.getInstance() instanceof MenuBar){
					mFrame.setMenuBar((MenuBar) child.getInstance());
					state = super.addChild(child);
				}else if(child.getInstance() instanceof Component){
					mFrame.add((Component) child.getInstance(),child.getProperty().get(Constants.CONSTRAINTS));
					state = super.addChild(child);
				}else{
					LogUtil.sysLog(TAG, "addChild Error:child is not extends Component");
				}
			}
		}
		return state;
	}
	public void setLabel(String label){
		super.setLabel(label);
		mFrame.setTitle(label);
	}
}
